package com.chen.listener;

import com.chen.pojo.Article;
import com.chen.pojo.Type;
import com.chen.service.ArticleService;
import com.chen.service.TypeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import java.util.List;


public class ApplicationListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
      /*  //加载spring的主配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //获取bean，这个bean就是service，SSM进行注册实体类实现service bean时所配的id名
        ArticleService articleService = context.getBean("articleService", ArticleService.class);
        //类别
        TypeService typeService = context.getBean("typeService", TypeService.class);

        //所有博客信息
        //List<Article> articles = articleService.allBlog(0,3);


        //所有类别信息
        List<Type> types = typeService.allType();
        //放入全局变量application
        ServletContext application = sce.getServletContext();

        //加入全局变量
        application.setAttribute("articles",articles);
        application.setAttribute("types",types);*/


    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
